package com.ruoyi.web.controller.net;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.net.domain.SysAlarmInfo;
import com.ruoyi.net.service.ISysAlarmInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 告警代码Controller
 * 
 * @author tony
 * @date 2025-02-16
 */
@Api(tags = "告警代码")
@RestController
@RequestMapping("/sys/alarm/info")
public class SysAlarmInfoController extends BaseController
{
    @Autowired
    private ISysAlarmInfoService sysAlarmInfoService;

    /**
     * 查询告警代码列表
     */
    @ApiOperation(value = "查询告警代码列表", httpMethod = "GET")
//    @PreAuthorize("@ss.hasPermi('net:system:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAlarmInfo sysAlarmInfo)
    {
        startPage();
        List<SysAlarmInfo> list = sysAlarmInfoService.selectSysAlarmInfoList(sysAlarmInfo);
        return getDataTable(list);
    }

    /**
     * 导出告警代码列表
     */
    @ApiOperation(value = "导出告警代码列表", httpMethod = "POST")
//    @PreAuthorize("@ss.hasPermi('net:system:export')")
    @Log(title = "告警代码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAlarmInfo sysAlarmInfo)
    {
        List<SysAlarmInfo> list = sysAlarmInfoService.selectSysAlarmInfoList(sysAlarmInfo);
        ExcelUtil<SysAlarmInfo> util = new ExcelUtil<SysAlarmInfo>(SysAlarmInfo.class);
        util.exportExcel(response, list, "告警代码数据");
    }

    /**
     * 获取告警代码详细信息
     */
    @ApiOperation(value = "获取告警代码详细信息", httpMethod = "GET")
//    @PreAuthorize("@ss.hasPermi('net:system:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(sysAlarmInfoService.selectSysAlarmInfoById(id));
    }

    /**
     * 新增告警代码
     */
    @ApiOperation(value = "新增告警代码", httpMethod = "POST")
//    @PreAuthorize("@ss.hasPermi('net:system:add')")
    @Log(title = "告警代码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAlarmInfo sysAlarmInfo)
    {
        return toAjax(sysAlarmInfoService.insertSysAlarmInfo(sysAlarmInfo));
    }

    /**
     * 修改告警代码
     */
    @ApiOperation(value = "修改告警代码", httpMethod = "PUT")
//    @PreAuthorize("@ss.hasPermi('net:system:edit')")
    @Log(title = "告警代码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAlarmInfo sysAlarmInfo)
    {
        return toAjax(sysAlarmInfoService.updateSysAlarmInfo(sysAlarmInfo));
    }

    /**
     * 删除告警代码
     */
    @ApiOperation(value = "删除告警代码", httpMethod = "DELETE")
//    @PreAuthorize("@ss.hasPermi('net:system:remove')")
    @Log(title = "告警代码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysAlarmInfoService.deleteSysAlarmInfoByIds(ids));
    }
}
